<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content">  
              
           
 
            <div class="Post">
                <h:form>
                    <div class="refBody">  <p:commandLink value="Create template" action="createTaskKantor" ajax="false"/>
                    </div>
                </h:form>
            </div>
          <br/>
            <div class="Post">

                <h:form id="taskForm">  
 <p:commandButton value="Next" action="#{kantorTaskBean.chooseTargetUsers()}" ajax="false" /> 
                    <p:dataTable 
                        var="template" value="#{kantorTaskBean.kantorTemplate}"  
                        selection="#{kantorTaskBean.selectedTemplate}" selectionMode="multiple"
                        rowKey="#{template.id}" paginator="true" paginatorAlwaysVisible="false" rows="10" >  
                        <f:facet name="header">  
                            <h:outputText value="Choose template to assign" />
                        </f:facet>  
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Template´s name" />  
                            </f:facet>  
                            <h:outputText value="#{template.name}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column>  

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Description" />  
                            </f:facet>  
                            <h:outputText value="#{template.description}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Created" />  
                            </f:facet>  
                            <h:outputText value="#{template.dateOfCreation}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Files"  />  
                            </f:facet>  
                            <p:commandButton value="Template files" action="#{kantorTaskBean.selectSingleTemplate(template)}" oncomplete="fileDialog.show()" update=":templateFiles" />

                        </p:column>  
                        <f:facet name="footer">      
                        </f:facet>  
                    </p:dataTable>  
                    <p:commandButton value="Next" action="#{kantorTaskBean.chooseTargetUsers()}" ajax="false" /> 
                </h:form>
                <p:dialog width="870" height="400" header="Submitted files with task:"
                          widgetVar="fileDialog" modal="true" closable="true" dynamic="true" appendToBody="true"
                          >
                    <h:form  id="templateFiles">
                        <p:dataTable var="file" value="#{kantorTaskBean.selectedSingleTemplate.templateFiles}"
                                     rowKey="#{file.id}" paginator="true" 
                                     paginatorAlwaysVisible="false" rows="10" >  
                            <p:column headerText="File" >  
                                <h:outputText title="file" value="#{file.fileName}"  />  
                            </p:column>
                            <p:column headerText="File size" >  
                                <h:outputText title="file" value="#{file.fileSize}"  />  
                            </p:column>                   
                            <p:column headerText="Download">  
                                <p:commandButton value="Download" ajax="false">  
                                    <p:fileDownload value="#{kantorTaskBean.download(file)}" />  
                                </p:commandButton> 
                            </p:column>    
                            <f:facet name="footer">
                                <h:outputText value=" "/>
                            </f:facet>
                        </p:dataTable>
                        <p:commandButton value="Close" oncomplete="fileDialog.hide()"  ajax="true"/>
                    </h:form>
                </p:dialog>
            </div>
        </ui:define>
    </ui:composition>
</html>